package view.swing;

import java.awt.CardLayout;
import java.awt.Component;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import view.ILogView;

import model.events.TurnEvent;
import model.swing.MoveListModel;

public class LogView implements ILogView {

    private JPanel panel = new JPanel();
    private JList list;

    public LogView() {
        super();
    }

    public LogView(MoveListModel mlm) {
        this();
        buildView(mlm);
    }

    private void buildView(MoveListModel mlm) {
        CardLayout cardLayout = new CardLayout();
        panel.setLayout(cardLayout);

        list = new JList(mlm);
        list.setVisible(true);
        list.setAutoscrolls(true);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scroll = new JScrollPane(list);
        scroll.setVisible(true);
        panel.add(scroll, "Center");
    }

    /* (non-Javadoc)
     * @see view.swing.ILogView#turnPlayed(model.events.TurnEvent)
     */
    @Override
    public void turnPlayed(TurnEvent event) {
        this.panel.updateUI();
    }

    public Component getPanel() {
        return panel;
    }
}
